package jehc.djshi.workflow.service.impl;

import jehc.djshi.common.base.BaseService;
import jehc.djshi.common.util.ExceptionUtil;
import jehc.djshi.common.util.StringUtil;
import jehc.djshi.workflow.dao.LcApprovalDao;
import jehc.djshi.workflow.model.LcApproval;
import jehc.djshi.workflow.service.LcApprovalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
import java.util.Map;

/**
 * @Desc 工作流批审
 * @Author 邓纯杰
 * @CreateTime 2012-12-12 12:12:12
 */
@Slf4j
@Service
public class LcApprovalServiceImpl extends BaseService implements LcApprovalService {
	@Autowired
	private LcApprovalDao lcApprovalDao;
	/**
	* 分页
	* @param condition 
	* @return
	*/
	public List<LcApproval> getLcApprovalListByCondition(Map<String,Object> condition){
		try{
			return lcApprovalDao.getLcApprovalListByCondition(condition);
		} catch (Exception e) {
			log.error("查询审批列表异常：{}",e);
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
	}
	/**
	* 查询对象
	* @param lcApprovalId
	* @return
	*/
	public LcApproval getLcApprovalById(String lcApprovalId){
		try{
			return lcApprovalDao.getLcApprovalById(lcApprovalId);
		} catch (Exception e) {
			log.error("查询审批记录异常：{}",e);
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
	}
	/**
	* 添加
	* @param lcApproval
	* @return
	*/
	public int addLcApproval(LcApproval lcApproval){
		int i = 0;
		try {
			if(StringUtil.isEmpty(lcApproval.getLcApprovalId())){
				lcApproval.setCreate_time(getDate());
				lcApproval.setCreate_id(getXtUid());
				lcApproval.setLcApprovalId(toUUID());
			}
			i = lcApprovalDao.addLcApproval(lcApproval);
		} catch (Exception e) {
			log.error("创建审批记录异常：{}",e);
			throw new ExceptionUtil("创建审批记录异常：{}",e.getCause());
		}
		return i;
	}

	/**
	* 删除
	* @param condition 
	* @return
	*/
	public int delLcApproval(Map<String,Object> condition){
		int i = 0;
		try {
			i = lcApprovalDao.delLcApproval(condition);
		} catch (Exception e) {
			log.error("删除审批记录异常：{}",e);
			throw new ExceptionUtil(e.getMessage(),e.getCause());
		}
		return i;
	}
}
